| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: User Access Manager |
| 4 |
Plugin URI: http://www.gm-alex.de/projects/wordpress/plugins/user-access-manager/ |
| 5 |
Author URI: http://www.gm-alex.de/ |
| 6 |
Version: 0.7 Beta |
| 7 |
Author: Alexander Schneider |
| 8 |
Description: Manage the access to your posts and pages. <strong>Note:</strong> <em>If you activate the plugin your upload dir will protect by a '.htaccess' with a random password and all old downloads insert in a previous post/page will not work anymore. You have to update your posts/pages. If you use already a '.htaccess' file to protect your files the plugin will not overwrite the '.htaccess'.</em> |
| 9 |
|
| 10 |
Copyright 2008 Alexander Schneider (email : alexanderschneider85 [at] gmail DOT com) |
| 11 |
|
| 12 |
This program is free software; you can redistribute it and/or modify |
| 13 |
it under the terms of the GNU General Public License as published by |
| 14 |
the Free Software Foundation; either version 2 of the License, or |
| 15 |
(at your option) any later version. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, |
| 18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
GNU General Public License for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License |
| 23 |
along with this program; if not, write to the Free Software |
| 24 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
|
| 26 |
*/ |
| 27 |
|
| 28 |
//DB |
| 29 |
global $wpdb; |
| 30 |
define('DB_ACCESSGROUP', $wpdb->prefix.'uam_accessgroups'); |
| 31 |
define('DB_ACCESSGROUP_TO_POST', $wpdb->prefix.'uam_accessgroup_to_post'); |
| 32 |
define('DB_ACCESSGROUP_TO_USER', $wpdb->prefix.'uam_accessgroup_to_user'); |
| 33 |
define('DB_ACCESSGROUP_TO_CATEGORY', $wpdb->prefix.'uam_accessgroup_to_category'); |
| 34 |
define('DB_ACCESSGROUP_TO_ROLE', $wpdb->prefix.'uam_accessgroup_to_role'); |
| 35 |
|
| 36 |
//PATH |
| 37 |
define('UAM_URLPATH', WP_CONTENT_URL.'/plugins/'.plugin_basename( dirname(__FILE__)).'/' ); |
| 38 |
|
| 39 |
//###Lang### |
| 40 |
|
| 41 |
//---Lang Settings--- |
| 42 |
define('TXT_SETTINGS', 'Settings'); |
| 43 |
|
| 44 |
define('TXT_POST_SETTING', 'Post settings'); |
| 45 |
define('TXT_POST_SETTING_DESC', 'Set up the behaviour of locked posts'); |
| 46 |
define('TXT_POST_TITLE', 'Post title'); |
| 47 |
define('TXT_POST_TITLE_DESC', 'Displayed text as post title if user has no access'); |
| 48 |
define('TXT_DISPLAY_POST_TITLE', 'Hide post titel'); |
| 49 |
define('TXT_DISPLAY_POST_TITLE_DESC', 'Selecting "Yes" will show the text which is defined at "'.TXT_POST_TITLE.'" if user has no access.'); |
| 50 |
define('TXT_POST_CONTENT', 'Post content'); |
| 51 |
define('TXT_POST_CONTENT_DESC', 'Content displayed if user has no access'); |
| 52 |
define('TXT_HIDE_POST', 'Hide complete posts'); |
| 53 |
define('TXT_HIDE_POST_DESC', 'Selecting "Yes" will hide posts if the user has no access.'); |
| 54 |
|
| 55 |
define('TXT_PAGE_SETTING', 'Page settings'); |
| 56 |
define('TXT_PAGE_SETTING_DESC', 'Set up the behaviour of locked pages'); |
| 57 |
define('TXT_PAGE_TITLE', 'Page title'); |
| 58 |
define('TXT_PAGE_TITLE_DESC', 'Displayed text as page title if user has no access'); |
| 59 |
define('TXT_DISPLAY_PAGE_TITLE', 'Hide page titel'); |
| 60 |
define('TXT_DISPLAY_PAGE_TITLE_DESC', 'Selecting "Yes" will show the text which is defined at "'.TXT_PAGE_TITLE.'" if user has no access.'); |
| 61 |
define('TXT_PAGE_CONTENT', 'Page content'); |
| 62 |
define('TXT_PAGE_CONTENT_DESC', 'Content displayed if user has no access'); |
| 63 |
define('TXT_HIDE_PAGE', 'Hide complete pages'); |
| 64 |
define('TXT_HIDE_PAGE_DESC', 'Selecting "Yes" will hide pages if the user has no access. Pages will also hide in the navigation.'); |
| 65 |
|
| 66 |
define('TXT_FILE_SETTING', 'File settings'); |
| 67 |
define('TXT_FILE_SETTING_DESC', 'Set up the behaviour of files'); |
| 68 |
define('TXT_LOCK_FILE', 'Lock files'); |
| 69 |
define('TXT_LOCK_FILE_DESC', 'If you select "Yes" all files will locked by a .htaccess file and only users with access can download files.'); |
| 70 |
define('TXT_DOWNLOAD_FILE_TYPE', 'Locked file types'); |
| 71 |
define('TXT_DOWNLOAD_FILE_TYPE_DESC', 'Type in file types which you will lock if the post/page is locked. <b>Note:</b> If you use images, vids or something else in your posts which are directly shown there and not for download do not type these types in here, because this types will not work anymore.'); |
| 72 |
define('TXT_DOWNLOAD_TYPE', 'Download type'); |
| 73 |
define('TXT_DOWNLOAD_TYPE_DESC', 'Selecting the type for downloading. <strong>Note:</strong> For using fopen you need "safe_mode = off".'); |
| 74 |
define('TXT_NORMAL', 'Normal'); |
| 75 |
define('TXT_FOPEN', 'fopen'); |
| 76 |
|
| 77 |
define('TXT_OTHER_SETTING', 'Other settings'); |
| 78 |
define('TXT_OTHER_SETTING_DESC', 'Here you will find all other settings'); |
| 79 |
define('TXT_REDIRECT', 'Redirect user'); |
| 80 |
define('TXT_REDIRECT_DESC', 'Setup what happen if a user visit a post/page with no access.'); |
| 81 |
define('TXT_REDIRECT_TO_BOLG', 'To blog startpage'); |
| 82 |
define('TXT_REDIRECT_TO_PAGE', 'Custom page: '); |
| 83 |
define('TXT_REDIRECT_TO_URL', 'Custom URL: '); |
| 84 |
define('TXT_LOCK_RECURSIVE', 'Lock recursive'); |
| 85 |
define('TXT_LOCK_RECURSIVE_DESC', 'Selecting "Yes" will lock all child posts/pages of a post/page if a user has no access to the parent page.'); |
| 86 |
|
| 87 |
define('TXT_YES', 'Yes'); |
| 88 |
define('TXT_NO', 'No'); |
| 89 |
|
| 90 |
define('TXT_UPDATE_SETTING', 'Update settings'); |
| 91 |
define('TXT_UPDATE_SETTINGS', 'Settings updated.'); |
| 92 |
|
| 93 |
//---Access groups--- |
| 94 |
|
| 95 |
define('TXT_MANAGE_GROUP', 'Manage user access groups'); |
| 96 |
define('TXT_GROUP_ROLE', 'Role affiliation'); |
| 97 |
define('TXT_NAME', 'Name'); |
| 98 |
define('TXT_DESCRIPTION', 'Description'); |
| 99 |
define('TXT_POSTS', 'Posts'); |
| 100 |
define('TXT_PAGES', 'Pages'); |
| 101 |
define('TXT_CATEGORY', 'Categories'); |
| 102 |
define('TXT_USERS', 'Users'); |
| 103 |
define('TXT_DELETE', 'Delete'); |
| 104 |
define('TXT_UPDATE_GROUP', 'Update group'); |
| 105 |
define('TXT_ADD', 'Add'); |
| 106 |
define('TXT_ADD_GROUP', 'Add access group'); |
| 107 |
define('TXT_GROUP_NAME', 'Access group name'); |
| 108 |
define('TXT_GROUP_NAME_DESC', 'The name is used to identify the access user group.'); |
| 109 |
define('TXT_GROUP_DESC', 'Access group description'); |
| 110 |
define('TXT_GROUP_DESC_DESC', 'The description of the group.'); |
| 111 |
define('TXT_GROUP_ADDED', 'Group was added successfully.'); |
| 112 |
define('TXT_DEL_GROUP', 'Group(s) was deleted successfully.'); |
| 113 |
define('TXT_NONE', 'none'); |
| 114 |
|
| 115 |
//---Misc--- |
| 116 |
define('TXT_FULL_ACCESS', 'Full access'); |
| 117 |
define('TXT_FULL_ACCESS_ADMIN', 'Full access (Administrator)'); |
| 118 |
define('TXT_NO_GROUP', 'No group'); |
| 119 |
define('TXT_SET_ACCESS', 'Set access'); |
| 120 |
|
| 121 |
define('TXT_DATE', 'Date'); |
| 122 |
define('TXT_TITLE', 'Title'); |
| 123 |
define('TXT_GROUP_ACCESS', 'Group access'); |
| 124 |
define('TXT_FULL_ACCESS', 'Full access'); |
| 125 |
define('TXT_USERNAME', 'Username'); |
| 126 |
|
| 127 |
define('TXT_MAIL', 'E-mail'); |
| 128 |
define('TXT_ACCESS', 'Access'); |
| 129 |
define('TXT_ADMIN_HINT', '<strong>Note:</strong> An administrator has allways access to all posts/pages.'); |
| 130 |
|
| 131 |
define('TXT_SET_POST_ACCESS', 'Set post access'); |
| 132 |
define('TXT_SET_PAGE_ACCESS', 'Set page access'); |
| 133 |
define('TXT_GROUPS', 'Access Groups'); |
| 134 |
define('TXT_CREATE_GROUP_FIRST', 'Please create a access group first.'); |
| 135 |
define('TXT_SET_USER_ACCESS', 'Set user access'); |
| 136 |
|
| 137 |
define('TXT_SET_UP_USERGROUPS', 'Set up usergroups'); |
| 138 |
|
| 139 |
|
| 140 |
if (!class_exists("UserAccessManager")) |
| 141 |
{ |
| 142 |
class UserAccessManager |
| 143 |
{ |
| 144 |
var $adminOptionsName = "uamAdminOptions"; |
| 145 |
var $atAdminPanel = false; |
| 146 |
|
| 147 |
function UserAccessManager() |
| 148 |
{ //constructor |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
function init() |
| 153 |
{ |
| 154 |
$this->getAdminOptions(); |
| 155 |
} |
| 156 |
|
| 157 |
function install() |
| 158 |
{ |
| 159 |
$this->create_htaccess(); |
| 160 |
$this->create_htpasswd(); |
| 161 |
|
| 162 |
global $wpdb; |
| 163 |
$uam_db_version = "1.0"; |
| 164 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 165 |
|
| 166 |
$charset_collate = ''; |
| 167 |
|
| 168 |
if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) |
| 169 |
{ |
| 170 |
if ( ! empty($wpdb->charset) ) |
| 171 |
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
| 172 |
if ( ! empty($wpdb->collate) ) |
| 173 |
$charset_collate .= " COLLATE $wpdb->collate"; |
| 174 |
} |
| 175 |
|
| 176 |
if($wpdb->get_var("show tables like '".DB_ACCESSGROUP."'") != DB_ACCESSGROUP) |
| 177 |
{ |
| 178 |
$sql = "CREATE TABLE " . DB_ACCESSGROUP . " ( |
| 179 |
ID int(11) NOT NULL auto_increment, |
| 180 |
groupname tinytext NOT NULL, |
| 181 |
groupdesc text NOT NULL, |
| 182 |
PRIMARY KEY (ID) |
| 183 |
) $charset_collate;"; |
| 184 |
|
| 185 |
dbDelta($sql); |
| 186 |
} |
| 187 |
|
| 188 |
if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_POST."'") != DB_ACCESSGROUP_TO_POST) |
| 189 |
{ |
| 190 |
$sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_POST . " ( |
| 191 |
post_id int(11) NOT NULL, |
| 192 |
group_id int(11) NOT NULL, |
| 193 |
PRIMARY KEY (post_id,group_id) |
| 194 |
) $charset_collate;"; |
| 195 |
|
| 196 |
dbDelta($sql); |
| 197 |
} |
| 198 |
|
| 199 |
if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_USER."'") != DB_ACCESSGROUP_TO_USER) |
| 200 |
{ |
| 201 |
$sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_USER . " ( |
| 202 |
user_id int(11) NOT NULL, |
| 203 |
group_id int(11) NOT NULL, |
| 204 |
PRIMARY KEY (user_id,group_id) |
| 205 |
) $charset_collate;"; |
| 206 |
|
| 207 |
dbDelta($sql); |
| 208 |
} |
| 209 |
|
| 210 |
if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_CATEGORY."'") != DB_ACCESSGROUP_TO_CATEGORY) |
| 211 |
{ |
| 212 |
$sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_CATEGORY . " ( |
| 213 |
category_id int(11) NOT NULL, |
| 214 |
group_id int(11) NOT NULL, |
| 215 |
PRIMARY KEY (category_id,group_id) |
| 216 |
) $charset_collate;"; |
| 217 |
|
| 218 |
dbDelta($sql); |
| 219 |
} |
| 220 |
|
| 221 |
if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_ROLE."'") != DB_ACCESSGROUP_TO_ROLE) |
| 222 |
{ |
| 223 |
$sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_ROLE . " ( |
| 224 |
role_name varchar(255) NOT NULL, |
| 225 |
group_id int(11) NOT NULL, |
| 226 |
PRIMARY KEY (role_name,group_id) |
| 227 |
) $charset_collate;"; |
| 228 |
|
| 229 |
dbDelta($sql); |
| 230 |
} |
| 231 |
|
| 232 |
add_option("uam_db_version", $uam_db_version); |
| 233 |
} |
| 234 |
|
| 235 |
function uninstall() |
| 236 |
{ |
| 237 |
global $wpdb; |
| 238 |
$wpdb->query("DROP TABLE ".DB_ACCESSGROUP.", ".DB_ACCESSGROUP_TO_POST.", ".DB_ACCESSGROUP_TO_USER); |
| 239 |
} |
| 240 |
|
| 241 |
function create_htaccess($create_new = false) |
| 242 |
{ |
| 243 |
// Make .htaccess file to protect data |
| 244 |
|
| 245 |
// get url |
| 246 |
$wud = wp_upload_dir(); |
| 247 |
$url = $DOCUMENT_ROOT.$wud['basedir']."/"; |
| 248 |
|
| 249 |
if(!file_exists($url.".htaccess") || $create_new) |
| 250 |
{ |
| 251 |
$areaname = "WP-Files"; |
| 252 |
|
| 253 |
$uamOptions = $this->getAdminOptions(); |
| 254 |
|
| 255 |
$file_types = $uamOptions['locked_file_types']; |
| 256 |
|
| 257 |
$file_types = str_replace(",", "|", $file_types); |
| 258 |
|
| 259 |
// make .htaccess and .htpasswd |
| 260 |
$htaccess_txt = "<FilesMatch '\.(".$file_types.")'>\n"; |
| 261 |
$htaccess_txt .= "AuthType Basic"."\n"; |
| 262 |
$htaccess_txt .= "AuthName \"".$areaname."\""."\n"; |
| 263 |
$htaccess_txt .= "AuthUserFile ".$url.".htpasswd"."\n"; |
| 264 |
$htaccess_txt .= "require valid-user"."\n"; |
| 265 |
$htaccess_txt .= "</FilesMatch>\n"; |
| 266 |
|
| 267 |
|
| 268 |
// save files |
| 269 |
$htaccess= fopen($url.".htaccess", "w"); |
| 270 |
fwrite($htaccess, $htaccess_txt); |
| 271 |
fclose($htaccess); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
function create_htpasswd($create_new = false) |
| 276 |
{ |
| 277 |
// get url |
| 278 |
$wud = wp_upload_dir(); |
| 279 |
$url = $DOCUMENT_ROOT.$wud['basedir']."/"; |
| 280 |
|
| 281 |
if(!file_exists($url.".htpasswd") || $create_new) |
| 282 |
{ |
| 283 |
$user = "admin"; |
| 284 |
|
| 285 |
# create password |
| 286 |
$array = array(); |
| 287 |
|
| 288 |
$length = 10; |
| 289 |
$capitals = true; |
| 290 |
|
| 291 |
if($length < 8) |
| 292 |
$length = mt_rand(8,20); |
| 293 |
|
| 294 |
# numbers |
| 295 |
for($i=48;$i<58;$i++) |
| 296 |
$array[] = chr($i); |
| 297 |
|
| 298 |
# small |
| 299 |
for($i=97;$i<122;$i++) |
| 300 |
$array[] = chr($i); |
| 301 |
|
| 302 |
# capitals |
| 303 |
if($capitals) |
| 304 |
for($i=65;$i<90;$i++) |
| 305 |
$array[] = chr($i); |
| 306 |
|
| 307 |
# specialchar: |
| 308 |
if($specialSigns) |
| 309 |
{ |
| 310 |
for($i=33;$i<47;$i++) |
| 311 |
$array[] = chr($i); |
| 312 |
for($i=59;$i<64;$i++) |
| 313 |
$array[] = chr($i); |
| 314 |
for($i=91;$i<96;$i++) |
| 315 |
$array[] = chr($i); |
| 316 |
for($i=123;$i<126;$i++) |
| 317 |
$array[] = chr($i); |
| 318 |
} |
| 319 |
|
| 320 |
mt_srand((double)microtime()*1000000); |
| 321 |
$password = ''; |
| 322 |
|
| 323 |
for ($i=1; $i<=$length; $i++) |
| 324 |
{ |
| 325 |
$rnd = mt_rand( 0, count($array)-1 ); |
| 326 |
$password .= $array[$rnd]; |
| 327 |
} |
| 328 |
|
| 329 |
// make .htpasswd |
| 330 |
$htpasswd_txt .= "$user:".md5($password)."\n"; |
| 331 |
|
| 332 |
// save file |
| 333 |
$htpasswd= fopen($url.".htpasswd", "w"); |
| 334 |
fwrite($htpasswd, $htpasswd_txt); |
| 335 |
fclose($htpasswd); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
function delete_htaccess_files() |
| 340 |
{ |
| 341 |
$wud = wp_upload_dir(); |
| 342 |
$url = $DOCUMENT_ROOT.$wud['basedir']."/"; |
| 343 |
unlink($url.".htaccess"); |
| 344 |
unlink($url.".htpasswd"); |
| 345 |
} |
| 346 |
|
| 347 |
//Returns an array of admin options |
| 348 |
function getAdminOptions() |
| 349 |
{ |
| 350 |
$uamAdminOptions = array( 'hide_post_title' => 'false', |
| 351 |
'post_title' => 'No rights!', |
| 352 |
'post_content' => 'Sorry no rights!', |
| 353 |
'hide_post' => 'false', |
| 354 |
'hide_page_title' => 'false', |
| 355 |
'page_title' => 'No rights!', |
| 356 |
'page_content' => 'Sorry you have no rights to view this page!', |
| 357 |
'hide_page' => 'false', |
| 358 |
'redirect' => 'false', |
| 359 |
'uam_redirect_custom_page' => '', |
| 360 |
'uam_redirect_custom_url' => '', |
| 361 |
'lock_recursive' => 'true', |
| 362 |
'lock_file' => 'true', |
| 363 |
'download_type' => 'fopen', |
| 364 |
'locked_file_types' => 'zip,rar,tar,gz,bz2'); |
| 365 |
|
| 366 |
$uamOptions = get_option($this->adminOptionsName); |
| 367 |
if (!empty($uamOptions)) { |
| 368 |
foreach ($uamOptions as $key => $option) |
| 369 |
$uamAdminOptions[$key] = $option; |
| 370 |
} |
| 371 |
update_option($this->adminOptionsName, $uamAdminOptions); |
| 372 |
return $uamAdminOptions; |
| 373 |
} |
| 374 |
|
| 375 |
//Prints out the admin page |
| 376 |
function printAdminPage() |
| 377 |
{ |
| 378 |
global $wpdb; |
| 379 |
|
| 380 |
$uamOptions = $this->getAdminOptions(); |
| 381 |
|
| 382 |
if (isset($_POST['update_uam_settings'])) |
| 383 |
{ |
| 384 |
if (isset($_POST['uam_hide_post_title'])) |
| 385 |
{ |
| 386 |
$uamOptions['hide_post_title'] = $_POST['uam_hide_post_title']; |
| 387 |
} |
| 388 |
if (isset($_POST['uam_post_title'])) |
| 389 |
{ |
| 390 |
$uamOptions['post_title'] = $_POST['uam_post_title']; |
| 391 |
} |
| 392 |
if (isset($_POST['uam_post_content'])) |
| 393 |
{ |
| 394 |
$uamOptions['post_content'] = $_POST['uam_post_content']; |
| 395 |
} |
| 396 |
if (isset($_POST['uam_hide_post'])) |
| 397 |
{ |
| 398 |
$uamOptions['hide_post'] = $_POST['uam_hide_post']; |
| 399 |
} |
| 400 |
if (isset($_POST['uam_hide_page_title'])) |
| 401 |
{ |
| 402 |
$uamOptions['hide_page_title'] = $_POST['uam_hide_page_title']; |
| 403 |
} |
| 404 |
if (isset($_POST['uam_page_title'])) |
| 405 |
{ |
| 406 |
$uamOptions['page_title'] = $_POST['uam_page_title']; |
| 407 |
} |
| 408 |
if (isset($_POST['uam_page_content'])) |
| 409 |
{ |
| 410 |
$uamOptions['page_content'] = $_POST['uam_page_content']; |
| 411 |
} |
| 412 |
if (isset($_POST['uam_hide_page'])) |
| 413 |
{ |
| 414 |
$uamOptions['hide_page'] = $_POST['uam_hide_page']; |
| 415 |
} |
| 416 |
if (isset($_POST['uam_redirect'])) |
| 417 |
{ |
| 418 |
$uamOptions['redirect'] = $_POST['uam_redirect']; |
| 419 |
} |
| 420 |
if (isset($_POST['uam_redirect_custom_page'])) |
| 421 |
{ |
| 422 |
$uamOptions['redirect_custom_page'] = $_POST['uam_redirect_custom_page']; |
| 423 |
} |
| 424 |
if (isset($_POST['uam_redirect_custom_url'])) |
| 425 |
{ |
| 426 |
$uamOptions['redirect_custom_url'] = $_POST['uam_redirect_custom_url']; |
| 427 |
} |
| 428 |
if (isset($_POST['uam_lock_recursive'])) |
| 429 |
{ |
| 430 |
$uamOptions['lock_recursive'] = $_POST['uam_lock_recursive']; |
| 431 |
} |
| 432 |
if (isset($_POST['uam_lock_file'])) |
| 433 |
{ |
| 434 |
if($_POST['uam_lock_file'] == 'false') |
| 435 |
{ |
| 436 |
if($uamOptions['lock_file'] != $_POST['uam_lock_file']) |
| 437 |
$this->delete_htaccess_files(); |
| 438 |
} |
| 439 |
else |
| 440 |
{ |
| 441 |
if($uamOptions['lock_file'] != $_POST['uam_lock_file']) |
| 442 |
$lock_file_changed = true; |
| 443 |
} |
| 444 |
$uamOptions['lock_file'] = $_POST['uam_lock_file']; |
| 445 |
} |
| 446 |
if (isset($_POST['uam_download_type'])) |
| 447 |
{ |
| 448 |
$uamOptions['download_type'] = $_POST['uam_download_type']; |
| 449 |
} |
| 450 |
if (isset($_POST['uam_locked_file_types'])) |
| 451 |
{ |
| 452 |
if($uamOptions['locked_file_types'] != $_POST['uam_locked_file_types']) |
| 453 |
$locked_file_types_changed = true; |
| 454 |
else |
| 455 |
$locked_file_types_changed = false; |
| 456 |
|
| 457 |
$uamOptions['locked_file_types'] = $_POST['uam_locked_file_types']; |
| 458 |
} |
| 459 |
|
| 460 |
update_option($this->adminOptionsName, $uamOptions); |
| 461 |
|
| 462 |
if(($locked_file_types_changed || $lock_file_changed) && $uamOptions['lock_file'] != 'false') |
| 463 |
{ |
| 464 |
$this->create_htaccess(true); |
| 465 |
$this->create_htpasswd(true); |
| 466 |
} |
| 467 |
?> |
| 468 |
<div class="updated"><p><strong><?php _e(TXT_UPDATE_SETTINGS, "UserAccessManager");?></strong></p></div> |
| 469 |
<?php |
| 470 |
} |
| 471 |
|
| 472 |
$cur_admin_page = $_GET['page']; |
| 473 |
$action = $_GET['action']; |
| 474 |
|
| 475 |
if($_POST['action'] == 'addgroup') |
| 476 |
{ |
| 477 |
$wpdb->query("INSERT INTO ".DB_ACCESSGROUP." (ID, groupname, groupdesc) VALUES(NULL, '".$_POST['access_group_name']."', '".$_POST['access_group_description']."')"); |
| 478 |
?> |
| 479 |
<div class="updated"><p><strong><?php _e(TXT_GROUP_ADDED, "UserAccessManager");?></strong></p></div> |
| 480 |
<?php |
| 481 |
} |
| 482 |
|
| 483 |
if($_POST['action'] == 'delgroup') |
| 484 |
{ |
| 485 |
$del_ids = $_POST['delete']; |
| 486 |
if($del_ids) |
| 487 |
{ |
| 488 |
foreach($del_ids as $del_id) |
| 489 |
{ |
| 490 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP." WHERE ID = $del_id LIMIT 1"); |
| 491 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE group_id = $del_id LIMIT 1"); |
| 492 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE group_id = $del_id LIMIT 1"); |
| 493 |
} |
| 494 |
?> |
| 495 |
<div class="updated"><p><strong><?php _e(TXT_DEL_GROUP, "UserAccessManager");?></strong></p></div> |
| 496 |
<?php |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
if($_POST['action'] == 'update_group') |
| 501 |
{ |
| 502 |
$wpdb->query(" UPDATE ".DB_ACCESSGROUP." |
| 503 |
SET groupname = '".$_POST['access_group_name']."', groupdesc = '".$_POST['access_group_description']."' |
| 504 |
WHERE ID = ".$_POST['access_group_id']); |
| 505 |
|
| 506 |
$roles = $_POST['roles']; |
| 507 |
if($roles) |
| 508 |
{ |
| 509 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_ROLE." WHERE group_id = ".$_POST['access_group_id']); |
| 510 |
foreach($roles as $role) |
| 511 |
{ |
| 512 |
$wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_ROLE." (group_id, role_name) VALUES('".$_POST['access_group_id']."', '".$role."')"); |
| 513 |
} |
| 514 |
} |
| 515 |
?> |
| 516 |
<div class="updated"><p><strong><?php _e("Access group edit successfully.", "UserAccessManager");?></strong></p></div> |
| 517 |
<?php |
| 518 |
} |
| 519 |
|
| 520 |
if($cur_admin_page == 'uam_usergroup' AND !$action) |
| 521 |
{ |
| 522 |
$accessgroups = $wpdb->get_results("SELECT * |
| 523 |
FROM ".DB_ACCESSGROUP." |
| 524 |
ORDER BY ID", ARRAY_A); |
| 525 |
?> |
| 526 |
<div class=wrap> |
| 527 |
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>"> |
| 528 |
<input type="hidden" value="delgroup" name="action"/> |
| 529 |
<h2><?php _e(TXT_MANAGE_GROUP, "UserAccessManager"); ?></h2> |
| 530 |
<div class="tablenav"> |
| 531 |
<div class="alignleft"> |
| 532 |
<input type="submit" class="button-secondary delete" name="deleteit" value="<?php _e(TXT_DELETE, "UserAccessManager"); ?>"/> |
| 533 |
</div> |
| 534 |
<br class="clear"/> |
| 535 |
</div> |
| 536 |
<br class="clear"/> |
| 537 |
<table class="widefat"> |
| 538 |
<thead> |
| 539 |
<tr class="thead"> |
| 540 |
<th scope="col"></th> |
| 541 |
<th scope="col"><?php _e(TXT_NAME, "UserAccessManager"); ?></th> |
| 542 |
<th scope="col"><?php _e(TXT_DESCRIPTION, "UserAccessManager"); ?></th> |
| 543 |
<th scope="col"><?php _e(TXT_POSTS, "UserAccessManager"); ?></th> |
| 544 |
<th scope="col"><?php _e(TXT_PAGES, "UserAccessManager"); ?></th> |
| 545 |
<th scope="col"><?php _e(TXT_CATEGORY, "UserAccessManager"); ?></th> |
| 546 |
<th scope="col"><?php _e(TXT_USERS, "UserAccessManager"); ?></th> |
| 547 |
</tr> |
| 548 |
</thead> |
| 549 |
<tbody> |
| 550 |
<?php |
| 551 |
if($accessgroups) |
| 552 |
{ |
| 553 |
foreach($accessgroups as $accessgroup) |
| 554 |
{ |
| 555 |
$users = $wpdb->get_results(" SELECT * |
| 556 |
FROM ".DB_ACCESSGROUP_TO_USER." |
| 557 |
WHERE group_id = ".$accessgroup['ID']." |
| 558 |
ORDER BY user_id", ARRAY_A); |
| 559 |
$posts = $wpdb->get_results(" SELECT * |
| 560 |
FROM ".DB_ACCESSGROUP_TO_POST." |
| 561 |
WHERE group_id = ".$accessgroup['ID']." |
| 562 |
ORDER BY post_id", ARRAY_A); |
| 563 |
$categories = $wpdb->get_results(" SELECT * |
| 564 |
FROM ".DB_ACCESSGROUP_TO_CATEGORY." |
| 565 |
WHERE group_id = ".$accessgroup['ID']." |
| 566 |
ORDER BY category_id", ARRAY_A); |
| 567 |
?> |
| 568 |
<tr class="alternate" id="group-<?php echo $accessgroup['ID']; ?>"> |
| 569 |
<th class="check-column" scope="row"><input type="checkbox" value="<?php echo $accessgroup['ID']; ?>" name="delete[]"/></th> |
| 570 |
<td><strong><a href="?page=<?php echo $cur_admin_page; ?>&action=edit_group&id=<?php echo $accessgroup['ID']; ?>"><?php echo $accessgroup['groupname']; ?></a></strong></td> |
| 571 |
<td><?php echo $accessgroup['groupdesc']; ?></td> |
| 572 |
<td> |
| 573 |
<?php |
| 574 |
if($posts) |
| 575 |
{ |
| 576 |
foreach($posts as $post) |
| 577 |
{ |
| 578 |
$cur_id = $post['post_id']; |
| 579 |
$cur_post = & get_post($cur_id); |
| 580 |
if($cur_post->post_type == 'post') |
| 581 |
echo "- ".$cur_post->post_title."<br />"; |
| 582 |
} |
| 583 |
} |
| 584 |
else |
| 585 |
{ |
| 586 |
_e(TXT_NONE, "UserAccessManager"); |
| 587 |
} |
| 588 |
?> |
| 589 |
</td> |
| 590 |
<td> |
| 591 |
<?php |
| 592 |
if($posts) |
| 593 |
{ |
| 594 |
foreach($posts as $post) |
| 595 |
{ |
| 596 |
$cur_id = $post['post_id']; |
| 597 |
$cur_post = & get_post($cur_id); |
| 598 |
if($cur_post->post_type == 'page') |
| 599 |
echo "- ".$cur_post->post_title."<br />"; |
| 600 |
} |
| 601 |
} |
| 602 |
else |
| 603 |
{ |
| 604 |
_e(TXT_NONE, "UserAccessManager"); |
| 605 |
} |
| 606 |
?> |
| 607 |
</td> |
| 608 |
<td> |
| 609 |
<?php |
| 610 |
if($categories) |
| 611 |
{ |
| 612 |
foreach($categories as $categorie) |
| 613 |
{ |
| 614 |
$cur_cat = get_category($categorie['category_id']); |
| 615 |
echo "- ".$cur_cat->cat_name."<br />"; |
| 616 |
} |
| 617 |
} |
| 618 |
else |
| 619 |
{ |
| 620 |
_e(TXT_NONE, "UserAccessManager"); |
| 621 |
} |
| 622 |
?> |
| 623 |
</td> |
| 624 |
<td> |
| 625 |
<?php |
| 626 |
if($users) |
| 627 |
{ |
| 628 |
foreach($users as $user) |
| 629 |
{ |
| 630 |
$cur_user = get_userdata($user['user_id']); |
| 631 |
echo "- ".$cur_user->nickname."<br />"; |
| 632 |
} |
| 633 |
} |
| 634 |
else |
| 635 |
{ |
| 636 |
_e(TXT_NONE, "UserAccessManager"); |
| 637 |
} |
| 638 |
?> |
| 639 |
</td> |
| 640 |
</tr> |
| 641 |
<?php |
| 642 |
} |
| 643 |
} |
| 644 |
?> |
| 645 |
</tbody> |
| 646 |
</table> |
| 647 |
</form> |
| 648 |
</div> |
| 649 |
<div class="wrap"> |
| 650 |
<h2><?php _e(TXT_ADD_GROUP, "UserAccessManager"); ?></h2> |
| 651 |
<div id="ajax-response"/> |
| 652 |
<form class="add:the-list: validate" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" id="addgroup" name="addgroup"> |
| 653 |
<input type="hidden" value="addgroup" name="action"/> |
| 654 |
<table class="form-table"> |
| 655 |
<tbody> |
| 656 |
<tr class="form-field form-required"> |
| 657 |
<th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_NAME, "UserAccessManager"); ?>e</label></th> |
| 658 |
<td><input type="text" aria-required="true" size="40" value="" id="access_group_name" name="access_group_name"/><br/> |
| 659 |
<?php _e(TXT_GROUP_NAME_DESC, "UserAccessManager"); ?></td> |
| 660 |
|
| 661 |
</tr> |
| 662 |
<tr class="form-field form-required"> |
| 663 |
<th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_DESC, "UserAccessManager"); ?></label></th> |
| 664 |
<td><input type="text" aria-required="true" size="40" value="" id="access_group_description" name="access_group_description"/><br/> |
| 665 |
<?php _e(TXT_GROUP_DESC_DESC, "UserAccessManager"); ?></td> |
| 666 |
</tr> |
| 667 |
<tr class="form-field form-required"> |
| 668 |
<th valign="top" scope="row"><label for="group_role"><?php _e(TXT_GROUP_ROLE, "UserAccessManager"); ?></label></th> |
| 669 |
<td> |
| 670 |
<?php |
| 671 |
global $wp_roles; |
| 672 |
|
| 673 |
foreach($wp_roles->role_names as $role => $name) |
| 674 |
{ |
| 675 |
?> |
| 676 |
<label class="selectit"> |
| 677 |
<input type="checkbox" value="<?php echo $role; ?>" name="roles[]"/> |
| 678 |
<?php echo $role ?> |
| 679 |
</label><br /> |
| 680 |
<?php |
| 681 |
} |
| 682 |
?> |
| 683 |
</td> |
| 684 |
</tr> |
| 685 |
</tbody> |
| 686 |
</table> |
| 687 |
<p class="submit"><input type="submit" value="<?php _e(TXT_ADD, "UserAccessManager"); ?>" name="submit" class="button"/></p> |
| 688 |
</form> |
| 689 |
</div> |
| 690 |
<?php |
| 691 |
} |
| 692 |
elseif($cur_admin_page == 'uam_settings' AND !$action) |
| 693 |
{ |
| 694 |
?> |
| 695 |
<div class=wrap> |
| 696 |
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>"> |
| 697 |
<h2><?php _e(TXT_SETTINGS, "UserAccessManager"); ?></h2> |
| 698 |
<h3><?php _e(TXT_POST_SETTING, "UserAccessManager"); ?></h3> |
| 699 |
<p><?php _e(TXT_POST_SETTING_DESC, "UserAccessManager"); ?></p> |
| 700 |
<table class="form-table"> |
| 701 |
<tbody> |
| 702 |
<tr valign="top"> |
| 703 |
<th scope="row"> |
| 704 |
<?php _e(TXT_POST_TITLE, "UserAccessManager"); ?> |
| 705 |
</th> |
| 706 |
<td> |
| 707 |
<input name="uam_post_title" value="<?php _e($uamOptions['post_title'], 'UserAccessManager') ?>" /> |
| 708 |
<br /> |
| 709 |
<?php _e(TXT_POST_TITLE_DESC, "UserAccessManager"); ?> |
| 710 |
</td> |
| 711 |
</tr> |
| 712 |
<tr valign="top"> |
| 713 |
<th scope="row"> |
| 714 |
<?php _e(TXT_DISPLAY_POST_TITLE, "UserAccessManager"); ?> |
| 715 |
</th> |
| 716 |
<td> |
| 717 |
<label for="uam_hide_post_title_yes"> |
| 718 |
<input type="radio" id="uam_hide_post_title_yes" name="uam_hide_post_title" value="true" <?php if ($uamOptions['hide_post_title'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 719 |
<?php _e(TXT_YES, "UserAccessManager"); ?> |
| 720 |
</label> |
| 721 |
<label for="uam_hide_post_title_no"> |
| 722 |
<input type="radio" id="uam_hide_post_title_no" name="uam_hide_post_title" value="false" <?php if ($uamOptions['hide_post_title'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 723 |
<?php _e(TXT_NO, "UserAccessManager"); ?> |
| 724 |
</label> |
| 725 |
<br /> |
| 726 |
<?php _e(TXT_DISPLAY_POST_TITLE_DESC, "UserAccessManager"); ?> |
| 727 |
</td> |
| 728 |
</tr> |
| 729 |
<tr valign="top"> |
| 730 |
<th scope="row"> |
| 731 |
<?php _e(TXT_POST_CONTENT, "UserAccessManager"); ?> |
| 732 |
</th> |
| 733 |
<td> |
| 734 |
<textarea name="uam_post_content" style="width: 80%; height: 100px;"><?php _e(apply_filters('format_to_edit',$uamOptions['post_content']), 'UserAccessManager') ?></textarea> |
| 735 |
<br /> |
| 736 |
<?php _e(TXT_POST_CONTENT_DESC, "UserAccessManager"); ?> |
| 737 |
</td> |
| 738 |
</tr> |
| 739 |
<tr valign="top"> |
| 740 |
<th scope="row"> |
| 741 |
<?php _e(TXT_HIDE_POST, "UserAccessManager"); ?> |
| 742 |
</th> |
| 743 |
<td> |
| 744 |
<label for="uam_hide_post_yes"> |
| 745 |
<input type="radio" id="uam_hide_post_yes" name="uam_hide_post" value="true" <?php if ($uamOptions['hide_post'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 746 |
<?php _e(TXT_YES, "UserAccessManager"); ?> |
| 747 |
</label> |
| 748 |
<label for="uam_hide_post_no"> |
| 749 |
<input type="radio" id="uam_hide_post_no" name="uam_hide_post" value="false" <?php if ($uamOptions['hide_post'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 750 |
<?php _e(TXT_NO, "UserAccessManager"); ?> |
| 751 |
</label> |
| 752 |
<br /> |
| 753 |
<?php _e(TXT_HIDE_POST_DESC, "UserAccessManager"); ?> |
| 754 |
</td> |
| 755 |
</tr> |
| 756 |
</tbody> |
| 757 |
</table> |
| 758 |
<h3><?php _e(TXT_PAGE_SETTING, "UserAccessManager"); ?></h3> |
| 759 |
<p><?php _e(TXT_PAGE_SETTING_DESC, "UserAccessManager"); ?></p> |
| 760 |
<table class="form-table"> |
| 761 |
<tbody> |
| 762 |
<tr> |
| 763 |
<th> |
| 764 |
<?php _e(TXT_PAGE_TITLE, "UserAccessManager"); ?> |
| 765 |
</th> |
| 766 |
<td> |
| 767 |
<input name="uam_page_title" value="<?php _e($uamOptions['page_title'], 'UserAccessManager') ?>" /> |
| 768 |
<br /> |
| 769 |
<?php _e(TXT_PAGE_TITLE_DESC, "UserAccessManager"); ?> |
| 770 |
</td> |
| 771 |
</tr> |
| 772 |
<tr valign="top"> |
| 773 |
<th scope="row"> |
| 774 |
<?php _e(TXT_DISPLAY_PAGE_TITLE, "UserAccessManager"); ?> |
| 775 |
</th> |
| 776 |
<td> |
| 777 |
<label for="uam_hide_page_title_yes"> |
| 778 |
<input type="radio" id="uam_hide_page_title_yes" name="uam_hide_page_title" value="true" <?php if ($uamOptions['hide_page_title'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 779 |
<?php _e(TXT_YES, "UserAccessManager"); ?> |
| 780 |
</label> |
| 781 |
<label for="uam_hide_page_title_no"> |
| 782 |
<input type="radio" id="uam_hide_page_title_no" name="uam_hide_page_title" value="false" <?php if ($uamOptions['hide_page_title'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 783 |
<?php _e(TXT_NO, "UserAccessManager"); ?> |
| 784 |
</label> |
| 785 |
<br /> |
| 786 |
<?php _e(TXT_DISPLAY_PAGE_TITLE_DESC, "UserAccessManager"); ?> |
| 787 |
</td> |
| 788 |
</tr> |
| 789 |
<tr> |
| 790 |
<th> |
| 791 |
<?php _e(TXT_PAGE_CONTENT, "UserAccessManager"); ?> |
| 792 |
</th> |
| 793 |
<td> |
| 794 |
<textarea name="uam_page_content" style="width: 80%; height: 100px;"><?php _e(apply_filters('format_to_edit',$uamOptions['page_content']), 'UserAccessManager') ?></textarea> |
| 795 |
<br /> |
| 796 |
<?php _e(TXT_PAGE_CONTENT_DESC, "UserAccessManager"); ?> |
| 797 |
</td> |
| 798 |
</tr> |
| 799 |
<tr> |
| 800 |
<th> |
| 801 |
<?php _e(TXT_HIDE_PAGE, "UserAccessManager"); ?> |
| 802 |
</th> |
| 803 |
<td> |
| 804 |
<label for="uam_hide_page_yes"> |
| 805 |
<input type="radio" id="uam_hide_page_yes" name="uam_hide_page" value="true" <?php if ($uamOptions['hide_page'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 806 |
<?php _e(TXT_YES, "UserAccessManager"); ?> |
| 807 |
</label> |
| 808 |
<label for="uam_hide_page_no"> |
| 809 |
<input type="radio" id="uam_hide_page_no" name="uam_hide_page" value="false" <?php if ($uamOptions['hide_page'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 810 |
<?php _e(TXT_NO, "UserAccessManager"); ?> |
| 811 |
</label> |
| 812 |
<br /> |
| 813 |
<?php _e(TXT_HIDE_PAGE_DESC, "UserAccessManager"); ?> |
| 814 |
</td> |
| 815 |
</tr> |
| 816 |
</tbody> |
| 817 |
</table> |
| 818 |
<h3><?php _e(TXT_FILE_SETTING, "UserAccessManager"); ?></h3> |
| 819 |
<p><?php _e(TXT_FILE_SETTING_DESC, "UserAccessManager"); ?></p> |
| 820 |
<table class="form-table"> |
| 821 |
<tbody> |
| 822 |
<tr> |
| 823 |
<th> |
| 824 |
<?php _e(TXT_LOCK_FILE, "UserAccessManager"); ?> |
| 825 |
</th> |
| 826 |
<td> |
| 827 |
<label for="uam_lock_file_yes"> |
| 828 |
<input type="radio" id="uam_lock_file_yes" name="uam_lock_file" value="true" <?php if ($uamOptions['lock_file'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 829 |
<?php _e(TXT_YES, "UserAccessManager"); ?> |
| 830 |
</label> |
| 831 |
<label for="uam_lock_file_no"> |
| 832 |
<input type="radio" id="uam_lock_file_no" name="uam_lock_file" value="false" <?php if ($uamOptions['lock_file'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 833 |
<?php _e(TXT_NO, "UserAccessManager"); ?> |
| 834 |
</label> |
| 835 |
<br /> |
| 836 |
<?php _e(TXT_LOCK_FILE_DESC, "UserAccessManager"); ?> |
| 837 |
</td> |
| 838 |
</tr> |
| 839 |
<tr> |
| 840 |
<th> |
| 841 |
<?php _e(TXT_DOWNLOAD_FILE_TYPE, "UserAccessManager"); ?> |
| 842 |
</th> |
| 843 |
<td> |
| 844 |
<input name="uam_locked_file_types" value="<?php _e($uamOptions['locked_file_types'], 'UserAccessManager') ?>" /> |
| 845 |
<br /> |
| 846 |
<?php _e(TXT_DOWNLOAD_FILE_TYPE_DESC, "UserAccessManager"); ?> |
| 847 |
</td> |
| 848 |
</tr> |
| 849 |
<tr> |
| 850 |
<th> |
| 851 |
<?php _e(TXT_DOWNLOAD_TYPE, "UserAccessManager"); ?> |
| 852 |
</th> |
| 853 |
<td> |
| 854 |
<label for="uam_download_type_normal"> |
| 855 |
<input type="radio" id="uam_download_type_normal" name="uam_download_type" value="normal" <?php if ($uamOptions['download_type'] == "normal") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 856 |
<?php _e(TXT_NORMAL, "UserAccessManager"); ?> |
| 857 |
</label> |
| 858 |
<label for="uam_download_type_fopen"> |
| 859 |
<input type="radio" id="uam_download_type_fopen" name="uam_download_type" value="fopen" <?php if ($uamOptions['download_type'] == "fopen") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 860 |
<?php _e(TXT_FOPEN, "UserAccessManager"); ?> |
| 861 |
</label> |
| 862 |
<br /> |
| 863 |
<?php _e(TXT_DOWNLOAD_TYPE_DESC, "UserAccessManager"); ?> |
| 864 |
</td> |
| 865 |
</tr> |
| 866 |
</tbody> |
| 867 |
</table> |
| 868 |
<h3><?php _e(TXT_OTHER_SETTING, "UserAccessManager"); ?></h3> |
| 869 |
<p><?php _e(TXT_OTHER_SETTING_DESC, "UserAccessManager"); ?></p> |
| 870 |
<table class="form-table"> |
| 871 |
<tbody> |
| 872 |
<tr> |
| 873 |
<th> |
| 874 |
<?php _e(TXT_REDIRECT, "UserAccessManager"); ?> |
| 875 |
</th> |
| 876 |
<td> |
| 877 |
<label for="uam_redirect_no"> |
| 878 |
<input type="radio" id="uam_redirect_no" name="uam_redirect" value="false" <?php if ($uamOptions['redirect'] == "false") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 879 |
<?php _e(TXT_NO, "UserAccessManager"); ?> |
| 880 |
</label> |
| 881 |
<label for="uam_redirect_blog"> |
| 882 |
<input type="radio" id="uam_redirect_blog" name="uam_redirect" value="blog" <?php if ($uamOptions['redirect'] == "blog") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 883 |
<?php _e(TXT_REDIRECT_TO_BOLG, "UserAccessManager"); ?> |
| 884 |
</label> |
| 885 |
<label for="uam_redirect_custom_page"> |
| 886 |
<input type="radio" id="uam_redirect_custom_p" name="uam_redirect" value="custom_page" <?php if ($uamOptions['redirect'] == "custom_page") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 887 |
<?php _e(TXT_REDIRECT_TO_PAGE, "UserAccessManager"); ?> |
| 888 |
</label><input name="uam_redirect_custom_page" value="<?php _e($uamOptions['redirect_custom_page'], 'UserAccessManager') ?>" /> |
| 889 |
<label for="uam_redirect_custom_url"> |
| 890 |
<input type="radio" id="uam_redirect_custom_u" name="uam_redirect" value="custom_url" <?php if ($uamOptions['redirect'] == "custom_url") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 891 |
<?php _e(TXT_REDIRECT_TO_URL, "UserAccessManager"); ?> |
| 892 |
</label><input name="uam_redirect_custom_url" value="<?php _e($uamOptions['redirect_custom_url'], 'UserAccessManager') ?>" /> |
| 893 |
<br /> |
| 894 |
<?php _e(TXT_REDIRECT_DESC, "UserAccessManager"); ?> |
| 895 |
</td> |
| 896 |
</tr> |
| 897 |
<tr> |
| 898 |
<th> |
| 899 |
<?php _e(TXT_LOCK_RECURSIVE, "UserAccessManager"); ?> |
| 900 |
</th> |
| 901 |
<td> |
| 902 |
<label for="uam_lock_recursive_yes"> |
| 903 |
<input type="radio" id="uam_lock_recursive_yes" name="uam_lock_recursive" value="true" <?php if ($uamOptions['lock_recursive'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> /> |
| 904 |
<?php _e(TXT_YES, "UserAccessManager"); ?> |
| 905 |
</label> |
| 906 |
<label for="uam_lock_recursive_no"> |
| 907 |
<input type="radio" id="uam_lock_recursive_no" name="uam_lock_recursive" value="false" <?php if ($uamOptions['lock_recursive'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/> |
| 908 |
<?php _e(TXT_NO, "UserAccessManager"); ?> |
| 909 |
</label> |
| 910 |
<br /> |
| 911 |
<?php _e(TXT_LOCK_RECURSIVE_DESC, "UserAccessManager"); ?> |
| 912 |
</td> |
| 913 |
</tr> |
| 914 |
</tbody> |
| 915 |
</table> |
| 916 |
<div class="submit"> |
| 917 |
<input type="submit" name="update_uam_settings" value="<?php _e(TXT_UPDATE_SETTING, 'UserAccessManager') ?>" /> |
| 918 |
</div> |
| 919 |
</form> |
| 920 |
</div> |
| 921 |
<?php |
| 922 |
} |
| 923 |
elseif($action == 'edit_group') |
| 924 |
{ |
| 925 |
$group_id = $_GET['id']; |
| 926 |
$accessgroup = $wpdb->get_row(" SELECT * |
| 927 |
FROM ".DB_ACCESSGROUP." |
| 928 |
WHERE ID = ".$group_id." |
| 929 |
LIMIT 1", ARRAY_A); |
| 930 |
?> |
| 931 |
<div class=wrap> |
| 932 |
<form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>"> |
| 933 |
<input type="hidden" value="update_group" name="action"/> |
| 934 |
<input type="hidden" value="<?php echo $group_id; ?>" name="access_group_id"/> |
| 935 |
<table class="form-table"> |
| 936 |
<tbody> |
| 937 |
<tr class="form-field form-required"> |
| 938 |
<th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_NAME, "UserAccessManager"); ?></label></th> |
| 939 |
<td><input type="text" aria-required="true" size="40" value="<?php echo $accessgroup["groupname"];?>" id="access_group_name" name="access_group_name"/><br/> |
| 940 |
<?php _e(TXT_GROUP_NAME_DESC, "UserAccessManager"); ?></td> |
| 941 |
</tr> |
| 942 |
<tr class="form-field form-required"> |
| 943 |
<th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_DESC, "UserAccessManager"); ?></label></th> |
| 944 |
<td><input type="text" aria-required="true" size="40" value="<?php echo $accessgroup["groupdesc"];?>" id="access_group_description" name="access_group_description"/><br/> |
| 945 |
<?php _e(TXT_GROUP_DESC_DESC, "UserAccessManager"); ?></td> |
| 946 |
</tr> |
| 947 |
<tr class="form-field form-required"> |
| 948 |
<th valign="top" scope="row"><label for="group_role"><?php _e(TXT_GROUP_ROLE, "UserAccessManager"); ?></label></th> |
| 949 |
<td> |
| 950 |
<?php |
| 951 |
global $wp_roles; |
| 952 |
|
| 953 |
foreach($wp_roles->role_names as $role => $name) |
| 954 |
{ |
| 955 |
$checked = $wpdb->get_results(" SELECT * |
| 956 |
FROM ".DB_ACCESSGROUP_TO_ROLE." |
| 957 |
WHERE role_name = '".$role."' |
| 958 |
AND group_id = ".$group_id, ARRAY_A) |
| 959 |
?> |
| 960 |
<label class="selectit"> |
| 961 |
<input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $role; ?>" name="roles[]"/> |
| 962 |
<?php echo $role ?> |
| 963 |
</label><br /> |
| 964 |
<?php |
| 965 |
} |
| 966 |
?> |
| 967 |
</td> |
| 968 |
</tr> |
| 969 |
</tbody> |
| 970 |
</table> |
| 971 |
<p class="submit"><input type="submit" value="<?php _e(TXT_UPDATE_GROUP, "UserAccessManager"); ?>" name="submit" class="button"/></p> |
| 972 |
</form> |
| 973 |
</div> |
| 974 |
<?php |
| 975 |
} |
| 976 |
}//End function printAdminPage() |
| 977 |
|
| 978 |
function get_usergroups_for_post($ID) |
| 979 |
{ |
| 980 |
global $wpdb; |
| 981 |
|
| 982 |
$access = $this->get_access($ID); |
| 983 |
|
| 984 |
$post_usergroups = array(); |
| 985 |
|
| 986 |
if($access->restricted_by_posts || $access->restricted_by_categories) |
| 987 |
{ |
| 988 |
if($access->restricted_by_posts) |
| 989 |
{ |
| 990 |
foreach($access->restricted_by_posts as $cur_id) |
| 991 |
{ |
| 992 |
$usergroups = $wpdb->get_results(" SELECT ag.groupname |
| 993 |
FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_POST." agtp |
| 994 |
WHERE agtp.post_id = ".$cur_id." |
| 995 |
AND ag.ID = agtp.group_id |
| 996 |
GROUP BY ag.groupname", ARRAY_A); |
| 997 |
|
| 998 |
if($usergroups) |
| 999 |
{ |
| 1000 |
foreach($usergroups as $usergroup) |
| 1001 |
{ |
| 1002 |
$cur_usergroup = $post_usergroups[$usergroup['groupname']]; |
| 1003 |
|
| 1004 |
$cur_usergroup->name = $usergroup['groupname']; |
| 1005 |
|
| 1006 |
if($cur_id != $ID) |
| 1007 |
{ |
| 1008 |
$posts = $cur_usergroup->posts; |
| 1009 |
|
| 1010 |
$lock_post = & get_post($cur_id); |
| 1011 |
$posts[] = $lock_post->ID; |
| 1012 |
$cur_usergroup->posts = $posts; |
| 1013 |
} |
| 1014 |
else |
| 1015 |
{ |
| 1016 |
$cur_usergroup->itself = true; |
| 1017 |
} |
| 1018 |
|
| 1019 |
$post_usergroups[$usergroup['groupname']] = $cur_usergroup; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
} |
| 1023 |
} |
| 1024 |
|
| 1025 |
if($access->restricted_by_categories) |
| 1026 |
{ |
| 1027 |
foreach($access->restricted_by_categories as $cur_id) |
| 1028 |
{ |
| 1029 |
$usergroups = $wpdb->get_results(" SELECT ag.groupname |
| 1030 |
FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_CATEGORY." agtc |
| 1031 |
WHERE agtc.category_id = ".$cur_id." |
| 1032 |
AND ag.ID = agtc.group_id |
| 1033 |
GROUP BY ag.groupname", ARRAY_A); |
| 1034 |
|
| 1035 |
if($usergroups) |
| 1036 |
{ |
| 1037 |
foreach($usergroups as $usergroup) |
| 1038 |
{ |
| 1039 |
$cur_usergroup = $post_usergroups[$usergroup['groupname']]; |
| 1040 |
|
| 1041 |
$cur_usergroup->name = $usergroup['groupname']; |
| 1042 |
|
| 1043 |
$categories = $cur_usergroup->categories; |
| 1044 |
|
| 1045 |
$lock_cat = & get_category($cur_id); |
| 1046 |
$categories[] = $lock_cat->term_id; |
| 1047 |
$cur_usergroup->categories = $categories; |
| 1048 |
|
| 1049 |
$post_usergroups[$usergroup['groupname']] = $cur_usergroup; |
| 1050 |
} |
| 1051 |
} |
| 1052 |
} |
| 1053 |
} |
| 1054 |
} |
| 1055 |
|
| 1056 |
return $post_usergroups; |
| 1057 |
} |
| 1058 |
|
| 1059 |
function add_post_columns_header($defaults) |
| 1060 |
{ |
| 1061 |
$defaults['access'] = __('Access'); |
| 1062 |
return $defaults; |
| 1063 |
} |
| 1064 |
|
| 1065 |
function add_post_column($column_name, $id) |
| 1066 |
{ |
| 1067 |
if( $column_name == 'access' ) |
| 1068 |
{ |
| 1069 |
$usergroups = $this->get_usergroups_for_post($id); |
| 1070 |
if($usergroups) |
| 1071 |
{ |
| 1072 |
foreach($usergroups as $usergroup) |
| 1073 |
{ |
| 1074 |
$output = "- ".$usergroup->name. ""; |
| 1075 |
$output .= " (Set by: "; |
| 1076 |
|
| 1077 |
if($usergroup->itself) |
| 1078 |
$output .= "itself, "; |
| 1079 |
|
| 1080 |
if($usergroup->posts) |
| 1081 |
{ |
| 1082 |
foreach($usergroup->posts as $cur_id) |
| 1083 |
{ |
| 1084 |
$cur_post = & get_post($cur_id); |
| 1085 |
$output .= "$cur_post->post_title [$cur_post->post_type], "; |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 1089 |
if($usergroup->categories) |
| 1090 |
{ |
| 1091 |
foreach($usergroup->categories as $cur_id) |
| 1092 |
{ |
| 1093 |
$cur_category = & get_category($cur_id); |
| 1094 |
$output .= "$cur_category->name [category], "; |
| 1095 |
} |
| 1096 |
} |
| 1097 |
|
| 1098 |
$output = substr($output, 0, -2); |
| 1099 |
|
| 1100 |
$output .= ")<br />"; |
| 1101 |
echo $output; |
| 1102 |
} |
| 1103 |
} |
| 1104 |
else |
| 1105 |
{ |
| 1106 |
_e(TXT_FULL_ACCESS, "UserAccessManager"); |
| 1107 |
} |
| 1108 |
} |
| 1109 |
} |
| 1110 |
|
| 1111 |
function edit_post_content($post) |
| 1112 |
{ |
| 1113 |
global $wpdb; |
| 1114 |
$accessgroups = $wpdb->get_results("SELECT * |
| 1115 |
FROM ".DB_ACCESSGROUP." |
| 1116 |
ORDER BY groupname", ARRAY_A); |
| 1117 |
if($accessgroups) |
| 1118 |
{ |
| 1119 |
foreach($accessgroups as $accessgroup) |
| 1120 |
{ |
| 1121 |
$checked = $wpdb->get_results(" SELECT * |
| 1122 |
FROM ".DB_ACCESSGROUP_TO_POST." |
| 1123 |
WHERE post_id = ".$post->ID." |
| 1124 |
AND group_id = ".$accessgroup['ID'], ARRAY_A) |
| 1125 |
?> |
| 1126 |
<p> |
| 1127 |
<label class="selectit" for="uam_accesss"> |
| 1128 |
<input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/> |
| 1129 |
<?php echo $accessgroup['groupname'] ?> |
| 1130 |
</label> |
| 1131 |
</p> |
| 1132 |
<?php |
| 1133 |
} |
| 1134 |
} |
| 1135 |
else |
| 1136 |
{ |
| 1137 |
echo "<p>"; |
| 1138 |
_e(TXT_CREATE_GROUP_FIRST, "UserAccessManager"); |
| 1139 |
echo "</p>"; |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
function save_postdata($post_id) |
| 1144 |
{ |
| 1145 |
global $wpdb; |
| 1146 |
$accessgroups = $_POST['accessgroups']; |
| 1147 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $post_id"); |
| 1148 |
if($accessgroups) |
| 1149 |
{ |
| 1150 |
foreach($accessgroups as $accessgroup) |
| 1151 |
{ |
| 1152 |
$wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_POST." (post_id,group_id) VALUES(".$post_id.", ".$accessgroup.")"); |
| 1153 |
} |
| 1154 |
} |
| 1155 |
} |
| 1156 |
|
| 1157 |
function remove_postdata($post_id) |
| 1158 |
{ |
| 1159 |
global $wpdb; |
| 1160 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $post_id"); |
| 1161 |
} |
| 1162 |
|
| 1163 |
function add_user_columns_header($defaults) |
| 1164 |
{ |
| 1165 |
$defaults['access'] = __('Access'); |
| 1166 |
return $defaults; |
| 1167 |
} |
| 1168 |
|
| 1169 |
function add_user_column($column_name, $id) |
| 1170 |
{ |
| 1171 |
global $wpdb; |
| 1172 |
|
| 1173 |
if( $column_name == 'access' ) |
| 1174 |
{ |
| 1175 |
$usergroups = $wpdb->get_results(" SELECT ag.groupname |
| 1176 |
FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_USER." agtp |
| 1177 |
WHERE agtp.user_id = ".$id." |
| 1178 |
AND ag.ID = agtp.group_id |
| 1179 |
GROUP BY ag.groupname", ARRAY_A); |
| 1180 |
|
| 1181 |
if($usergroups) |
| 1182 |
{ |
| 1183 |
foreach($usergroups as $usergroup) |
| 1184 |
{ |
| 1185 |
$content .= $usergroup['groupname']."<br />"; |
| 1186 |
} |
| 1187 |
} |
| 1188 |
else |
| 1189 |
{ |
| 1190 |
$content = TXT_NO_GROUP; |
| 1191 |
} |
| 1192 |
return $content; |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
function show_user_profile() |
| 1197 |
{ |
| 1198 |
global $wpdb, $current_user; |
| 1199 |
|
| 1200 |
$user_id = $_GET['user_id']; |
| 1201 |
$cur_userdata = get_userdata($current_user->ID); |
| 1202 |
$cur_edit_userdata = get_userdata($user_id); |
| 1203 |
|
| 1204 |
if($cur_userdata->wp_capabilities['administrator'] == 1) |
| 1205 |
{ |
| 1206 |
$accessgroups = $wpdb->get_results("SELECT * |
| 1207 |
FROM ".DB_ACCESSGROUP." |
| 1208 |
ORDER BY groupname", ARRAY_A); |
| 1209 |
|
| 1210 |
?> |
| 1211 |
<h3><?php _e(TXT_GROUPS, "UserAccessManager"); ?></h3> |
| 1212 |
<table class="form-table"> |
| 1213 |
<tbody> |
| 1214 |
<tr> |
| 1215 |
<th> |
| 1216 |
<label for="usergroups"><?php _e(TXT_SET_UP_USERGROUPS, "UserAccessManager"); ?></label> |
| 1217 |
</th> |
| 1218 |
<td> |
| 1219 |
<?php |
| 1220 |
if($cur_edit_userdata->wp_capabilities['administrator'] != 1) |
| 1221 |
{ |
| 1222 |
if($accessgroups) |
| 1223 |
{ |
| 1224 |
foreach($accessgroups as $accessgroup) |
| 1225 |
{ |
| 1226 |
$checked = $wpdb->get_results(" SELECT * |
| 1227 |
FROM ".DB_ACCESSGROUP_TO_USER." |
| 1228 |
WHERE user_id = ".$user_id." |
| 1229 |
AND group_id = ".$accessgroup['ID'], ARRAY_A) |
| 1230 |
?> |
| 1231 |
<label class="selectit"> |
| 1232 |
<input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/> |
| 1233 |
<?php echo $accessgroup['groupname'] ?> |
| 1234 |
</label><br /> |
| 1235 |
<?php |
| 1236 |
} |
| 1237 |
} |
| 1238 |
else |
| 1239 |
{ |
| 1240 |
_e(TXT_CREATE_GROUP_FIRST, "UserAccessManager"); |
| 1241 |
} |
| 1242 |
} |
| 1243 |
else |
| 1244 |
{ |
| 1245 |
_e(TXT_ADMIN_HINT, "UserAccessManager"); |
| 1246 |
} |
| 1247 |
?> |
| 1248 |
</td> |
| 1249 |
</tr> |
| 1250 |
</tbody> |
| 1251 |
</table> |
| 1252 |
<?php |
| 1253 |
} |
| 1254 |
} |
| 1255 |
|
| 1256 |
function save_userdata($user_id) |
| 1257 |
{ |
| 1258 |
global $wpdb, $current_user; |
| 1259 |
|
| 1260 |
$cur_userdata = get_userdata($current_user->ID); |
| 1261 |
|
| 1262 |
if($cur_userdata->wp_capabilities['administrator'] == 1) |
| 1263 |
{ |
| 1264 |
$accessgroups = $_POST['accessgroups']; |
| 1265 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE user_id = $user_id"); |
| 1266 |
if($accessgroups) |
| 1267 |
{ |
| 1268 |
foreach($accessgroups as $accessgroup) |
| 1269 |
{ |
| 1270 |
$wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_USER." (user_id,group_id) VALUES(".$user_id.", ".$accessgroup.")"); |
| 1271 |
} |
| 1272 |
} |
| 1273 |
} |
| 1274 |
} |
| 1275 |
|
| 1276 |
function remove_userdata($user_id) |
| 1277 |
{ |
| 1278 |
global $wpdb, $current_user; |
| 1279 |
|
| 1280 |
$cur_userdata = get_userdata($current_user->ID); |
| 1281 |
|
| 1282 |
if($cur_userdata->wp_capabilities['administrator'] == 1) |
| 1283 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE user_id = $user_id"); |
| 1284 |
} |
| 1285 |
|
| 1286 |
function add_category_columns_header($defaults) |
| 1287 |
{ |
| 1288 |
$defaults['access'] = __('Access'); |
| 1289 |
return $defaults; |
| 1290 |
} |
| 1291 |
|
| 1292 |
function add_category_column($column_name, $id) |
| 1293 |
{ |
| 1294 |
global $wpdb; |
| 1295 |
|
| 1296 |
if( $column_name == 'access' ) |
| 1297 |
{ |
| 1298 |
$usergroups = $wpdb->get_results(" SELECT ag.groupname |
| 1299 |
FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_CATEGORY." agtc |
| 1300 |
WHERE agtc.category_id = ".$id." |
| 1301 |
AND ag.ID = agtc.group_id |
| 1302 |
GROUP BY ag.groupname", ARRAY_A); |
| 1303 |
|
| 1304 |
if($usergroups) |
| 1305 |
{ |
| 1306 |
foreach($usergroups as $usergroup) |
| 1307 |
{ |
| 1308 |
$content .= "- ".$usergroup['groupname']."<br />"; |
| 1309 |
} |
| 1310 |
} |
| 1311 |
else |
| 1312 |
{ |
| 1313 |
$content = TXT_NO_GROUP; |
| 1314 |
} |
| 1315 |
return $content; |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
function show_cat_add_form($cat) |
| 1320 |
{ |
| 1321 |
global $wpdb, $current_user; |
| 1322 |
|
| 1323 |
$cat_id = $cat->cat_ID; |
| 1324 |
|
| 1325 |
$accessgroups = $wpdb->get_results("SELECT * |
| 1326 |
FROM ".DB_ACCESSGROUP." |
| 1327 |
ORDER BY groupname", ARRAY_A); |
| 1328 |
|
| 1329 |
?> |
| 1330 |
<div class="form-field"> |
| 1331 |
<label for="usergroups"><?php _e(TXT_SET_UP_USERGROUPS, "UserAccessManager"); ?></label> |
| 1332 |
<?php |
| 1333 |
if($accessgroups) |
| 1334 |
{ |
| 1335 |
foreach($accessgroups as $accessgroup) |
| 1336 |
{ |
| 1337 |
$checked = $wpdb->get_results(" SELECT * |
| 1338 |
FROM ".DB_ACCESSGROUP_TO_CATEGORY." |
| 1339 |
WHERE category_id = ".$cat_id." |
| 1340 |
AND group_id = ".$accessgroup['ID'], ARRAY_A) |
| 1341 |
?> |
| 1342 |
<label class="selectit"> |
| 1343 |
<input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/> |
| 1344 |
<?php echo $accessgroup['groupname'] ?> |
| 1345 |
</label> |
| 1346 |
<?php |
| 1347 |
} |
| 1348 |
} |
| 1349 |
else |
| 1350 |
{ |
| 1351 |
_e(TXT_CREATE_GROUP_FIRST, "UserAccessManager"); |
| 1352 |
} |
| 1353 |
?> |
| 1354 |
</div> |
| 1355 |
<?php |
| 1356 |
} |
| 1357 |
|
| 1358 |
function show_cat_edit_form($cat) |
| 1359 |
{ |
| 1360 |
global $wpdb, $current_user; |
| 1361 |
|
| 1362 |
$cat_id = $cat->cat_ID; |
| 1363 |
|
| 1364 |
$accessgroups = $wpdb->get_results("SELECT * |
| 1365 |
FROM ".DB_ACCESSGROUP." |
| 1366 |
ORDER BY groupname", ARRAY_A); |
| 1367 |
|
| 1368 |
?> |
| 1369 |
<table class="form-table"> |
| 1370 |
<tbody> |
| 1371 |
<tr> |
| 1372 |
<th> |
| 1373 |
<label for="description"><?php _e(TXT_SET_UP_USERGROUPS, "UserAccessManager"); ?></label> |
| 1374 |
</th> |
| 1375 |
<td> |
| 1376 |
<?php |
| 1377 |
if($accessgroups) |
| 1378 |
{ |
| 1379 |
foreach($accessgroups as $accessgroup) |
| 1380 |
{ |
| 1381 |
$checked = $wpdb->get_results(" SELECT * |
| 1382 |
FROM ".DB_ACCESSGROUP_TO_CATEGORY." |
| 1383 |
WHERE category_id = ".$cat_id." |
| 1384 |
AND group_id = ".$accessgroup['ID'], ARRAY_A) |
| 1385 |
?> |
| 1386 |
<label class="selectit"> |
| 1387 |
<input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/> |
| 1388 |
<?php echo $accessgroup['groupname'] ?> |
| 1389 |
</label><br /> |
| 1390 |
<?php |
| 1391 |
} |
| 1392 |
} |
| 1393 |
else |
| 1394 |
{ |
| 1395 |
_e(TXT_CREATE_GROUP_FIRST, "UserAccessManager"); |
| 1396 |
} |
| 1397 |
?> |
| 1398 |
</td> |
| 1399 |
</tr> |
| 1400 |
</tbody> |
| 1401 |
</table> |
| 1402 |
<?php |
| 1403 |
} |
| 1404 |
|
| 1405 |
function add_head_content() |
| 1406 |
{ |
| 1407 |
wp_enqueue_style('UserAccessManager', UAM_URLPATH."css/uma_admin.css" , false, '1.0.0', 'screen'); |
| 1408 |
} |
| 1409 |
|
| 1410 |
function save_categorydata($category_id) |
| 1411 |
{ |
| 1412 |
global $wpdb; |
| 1413 |
|
| 1414 |
$accessgroups = $_POST['accessgroups']; |
| 1415 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_CATEGORY." WHERE category_id = $category_id"); |
| 1416 |
if($accessgroups) |
| 1417 |
{ |
| 1418 |
foreach($accessgroups as $accessgroup) |
| 1419 |
{ |
| 1420 |
$wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_CATEGORY." (category_id,group_id) VALUES(".$category_id.", ".$accessgroup.")"); |
| 1421 |
} |
| 1422 |
} |
| 1423 |
} |
| 1424 |
|
| 1425 |
function remove_categorydata($category_id) |
| 1426 |
{ |
| 1427 |
global $wpdb; |
| 1428 |
|
| 1429 |
$wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_CATEGORY." WHERE category_id = $category_id"); |
| 1430 |
} |
| 1431 |
|
| 1432 |
function get_access($post_id) |
| 1433 |
{ |
| 1434 |
global $wpdb; |
| 1435 |
|
| 1436 |
$cur_id = $post_id; |
| 1437 |
$cur_post = & get_post($cur_id); |
| 1438 |
$cur_categories = get_the_category($cur_id); |
| 1439 |
|
| 1440 |
$uamOptions = $this->getAdminOptions(); |
| 1441 |
|
| 1442 |
|
| 1443 |
//check categories access |
| 1444 |
foreach($cur_categories as $cur_category) |
| 1445 |
{ |
| 1446 |
if($uamOptions['lock_recursive'] == 'true') |
| 1447 |
{ |
| 1448 |
$cur_id = $cur_category->term_id; |
| 1449 |
while($cur_id != 0) |
| 1450 |
{ |
| 1451 |
$restricted_access_by_cat = $wpdb->get_results(" SELECT * |
| 1452 |
FROM ".DB_ACCESSGROUP_TO_CATEGORY." |
| 1453 |
WHERE category_id = ".$cur_category->term_id, ARRAY_A); |
| 1454 |
if($restricted_access_by_cat) |
| 1455 |
$restricted_by_categories[] = $cur_category->term_id; |
| 1456 |
|
| 1457 |
$cur_id = $cur_category->parent; |
| 1458 |
$cur_category = get_the_category($cur_id); |
| 1459 |
} |
| 1460 |
} |
| 1461 |
elseif($uamOptions['lock_recursive'] == 'false') |
| 1462 |
{ |
| 1463 |
$restricted_access_by_cat = $wpdb->get_results(" SELECT * |
| 1464 |
FROM ".DB_ACCESSGROUP_TO_CATEGORY." |
| 1465 |
WHERE category_id = ".$cur_category->term_id, ARRAY_A); |
| 1466 |
if($restricted_access_by_cat) |
| 1467 |
$restricted_by_categories[] = $cur_category->term_id; |
| 1468 |
} |
| 1469 |
} |
| 1470 |
|
| 1471 |
//check posts access |
| 1472 |
if($uamOptions['lock_recursive'] == 'true') |
| 1473 |
{ |
| 1474 |
$cur_id = $cur_post->ID; |
| 1475 |
while($cur_id != 0) |
| 1476 |
{ |
| 1477 |
$restricted_access_by_post = $wpdb->get_results(" SELECT * |
| 1478 |
FROM ".DB_ACCESSGROUP_TO_POST." |
| 1479 |
WHERE post_id = ".$cur_post->ID, ARRAY_A); |
| 1480 |
if($restricted_access_by_post) |
| 1481 |
$restricted_by_posts[] = $cur_post->ID; |
| 1482 |
|
| 1483 |
$cur_id = $cur_post->post_parent; |
| 1484 |
$cur_post = & get_post($cur_id); |
| 1485 |
} |
| 1486 |
} |
| 1487 |
elseif($uamOptions['lock_recursive'] == 'false') |
| 1488 |
{ |
| 1489 |
if( $cur_post->post_type != 'attachment') |
| 1490 |
{ |
| 1491 |
$restricted_access_by_post = $wpdb->get_results(" SELECT * |
| 1492 |
FROM ".DB_ACCESSGROUP_TO_POST." |
| 1493 |
WHERE post_id = ".$cur_post->ID, ARRAY_A); |
| 1494 |
} |
| 1495 |
else |
| 1496 |
{ |
| 1497 |
$restricted_access_by_post = $wpdb->get_results(" SELECT * |
| 1498 |
FROM ".DB_ACCESSGROUP_TO_POST." |
| 1499 |
WHERE post_id = ".$cur_post->post_parent, ARRAY_A); |
| 1500 |
} |
| 1501 |
if($restricted_access_by_post) |
| 1502 |
$restricted_by_posts[] = $cur_post->ID; |
| 1503 |
} |
| 1504 |
|
| 1505 |
$access->restricted_by_categories = $restricted_by_categories; |
| 1506 |
$access->restricted_by_posts = $restricted_by_posts; |
| 1507 |
|
| 1508 |
return $access; |
| 1509 |
} |
| 1510 |
|
| 1511 |
function check_access($post_id = null) |
| 1512 |
{ |
| 1513 |
global $wpdb, $current_user; |
| 1514 |
|
| 1515 |
$access = $this->get_access($post_id); |
| 1516 |
|
| 1517 |
if($access->restricted_by_posts || $access->restricted_by_categories) |
| 1518 |
{ |
| 1519 |
if(is_user_logged_in()) |
| 1520 |
{ |
| 1521 |
$cur_userdata = get_userdata($current_user->ID); |
| 1522 |
|
| 1523 |
if($cur_userdata->wp_capabilities['administrator'] != 1) |
| 1524 |
{ |
| 1525 |
if($access->restricted_by_categories) |
| 1526 |
{ |
| 1527 |
foreach($access->restricted_by_categories as $cur_cat_id) |
| 1528 |
{ |
| 1529 |
$user_access = $wpdb->get_results(" SELECT * |
| 1530 |
FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP_TO_USER." atu |
| 1531 |
WHERE atc.category_id = ".$cur_cat_id." |
| 1532 |
AND atc.group_id = atu.group_id |
| 1533 |
AND atu.user_id = ".$current_user->ID, ARRAY_A); |
| 1534 |
if($user_access) |
| 1535 |
return true; |
| 1536 |
|
| 1537 |
$access_roles = $wpdb->get_results("SELECT atr.role_name |
| 1538 |
FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP_TO_ROLE." atr |
| 1539 |
WHERE atc.category_id = ".$cur_cat_id." |
| 1540 |
AND atc.group_id = atr.group_id", ARRAY_A); |
| 1541 |
|
| 1542 |
if($access_roles) |
| 1543 |
{ |
| 1544 |
foreach($access_roles as $access_role) |
| 1545 |
{ |
| 1546 |
if($cur_userdata->wp_capabilities[$access_role['role_name']] == 1) |
| 1547 |
return true; |
| 1548 |
} |
| 1549 |
} |
| 1550 |
} |
| 1551 |
} |
| 1552 |
|
| 1553 |
if($access->restricted_by_posts) |
| 1554 |
{ |
| 1555 |
foreach($access->restricted_by_posts as $cur_post_id) |
| 1556 |
{ |
| 1557 |
$user_access = $wpdb->get_results(" SELECT * |
| 1558 |
FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP_TO_USER." atu |
| 1559 |
WHERE atp.post_id = ".$cur_post_id." |
| 1560 |
AND atp.group_id = atu.group_id |
| 1561 |
AND atu.user_id = ".$current_user->ID, ARRAY_A); |
| 1562 |
if($user_access) |
| 1563 |
return true; |
| 1564 |
|
| 1565 |
$access_roles = $wpdb->get_results("SELECT atr.role_name |
| 1566 |
FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP_TO_ROLE." atr |
| 1567 |
WHERE atp.post_id = ".$cur_post_id." |
| 1568 |
AND atp.group_id = atr.group_id", ARRAY_A); |
| 1569 |
if($access_roles) |
| 1570 |
{ |
| 1571 |
foreach($access_roles as $access_role) |
| 1572 |
{ |
| 1573 |
if($cur_userdata->wp_capabilities[$access_role['role_name']] == 1) |
| 1574 |
return true; |
| 1575 |
} |
| 1576 |
} |
| 1577 |
} |
| 1578 |
} |
| 1579 |
|
| 1580 |
if(!$user_access) |
| 1581 |
return false; |
| 1582 |
} |
| 1583 |
else |
| 1584 |
{ |
| 1585 |
return true; |
| 1586 |
} |
| 1587 |
} |
| 1588 |
else |
| 1589 |
{ |
| 1590 |
return false; |
| 1591 |
} |
| 1592 |
} |
| 1593 |
else |
| 1594 |
{ |
| 1595 |
return true; |
| 1596 |
} |
| 1597 |
} |
| 1598 |
|
| 1599 |
function show_post($posts = array()) |
| 1600 |
{ |
| 1601 |
$no_posts = count($posts); |
| 1602 |
$uamOptions = $this->getAdminOptions(); |
| 1603 |
|
| 1604 |
for($i=0; $i < $no_posts; $i++) |
| 1605 |
{ |
| 1606 |
if( ($uamOptions['hide_post'] == 'true' && $posts[$i]->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $posts[$i]->post_type == "page") ) |
| 1607 |
{ |
| 1608 |
if($this->check_access($posts[$i]->ID)) |
| 1609 |
{ |
| 1610 |
$posts[$i]->post_title .= $this->admin_output($posts[$i]->ID); |
| 1611 |
$show_posts[] = $posts[$i]; |
| 1612 |
} |
| 1613 |
} |
| 1614 |
else |
| 1615 |
{ |
| 1616 |
if(!$this->check_access($posts[$i]->ID)) |
| 1617 |
{ |
| 1618 |
if($posts[$i]->post_type == "post") |
| 1619 |
{ |
| 1620 |
if($uamOptions['hide_post_title'] == 'true') |
| 1621 |
$posts[$i]->post_title = $uamOptions['post_title']; |
| 1622 |
|
| 1623 |
$posts[$i]->post_content = $uamOptions['post_content']; |
| 1624 |
} |
| 1625 |
elseif($posts[$i]->post_type == "page") |
| 1626 |
{ |
| 1627 |
if($uamOptions['hide_page_title'] == 'true') |
| 1628 |
$posts[$i]->post_title = $uamOptions['page_title']; |
| 1629 |
|
| 1630 |
$posts[$i]->post_content = $uamOptions['page_content']; |
| 1631 |
} |
| 1632 |
} |
| 1633 |
$posts[$i]->post_title .= $this->admin_output($posts[$i]->ID); |
| 1634 |
$show_posts[] = $posts[$i]; |
| 1635 |
} |
| 1636 |
|
| 1637 |
} |
| 1638 |
|
| 1639 |
$posts = $show_posts; |
| 1640 |
|
| 1641 |
return $posts; |
| 1642 |
} |
| 1643 |
|
| 1644 |
function show_page($pages = array()) |
| 1645 |
{ |
| 1646 |
$no_pages = count($pages); |
| 1647 |
$uamOptions = $this->getAdminOptions(); |
| 1648 |
|
| 1649 |
for($i=0; $i < $no_pages; $i++) |
| 1650 |
{ |
| 1651 |
if($uamOptions['hide_page'] == 'true') |
| 1652 |
{ |
| 1653 |
if($this->check_access($pages[$i]->ID)) |
| 1654 |
{ |
| 1655 |
$pages[$i]->post_title .= $this->admin_output($pages[$i]->ID); |
| 1656 |
$show_pages[] = $pages[$i]; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
else |
| 1660 |
{ |
| 1661 |
if(!$this->check_access($pages[$i]->ID)) |
| 1662 |
{ |
| 1663 |
if($uamOptions['hide_page_title'] == 'true') |
| 1664 |
$pages[$i]->post_title = $uamOptions['page_title']; |
| 1665 |
|
| 1666 |
$pages[$i]->post_content = $uamOptions['page_content']; |
| 1667 |
} |
| 1668 |
$pages[$i]->post_title .= $this->admin_output($pages[$i]->ID); |
| 1669 |
$show_pages[] = $pages[$i]; |
| 1670 |
} |
| 1671 |
|
| 1672 |
} |
| 1673 |
|
| 1674 |
$pages = $show_pages; |
| 1675 |
|
| 1676 |
return $pages; |
| 1677 |
} |
| 1678 |
|
| 1679 |
function show_category($categories) |
| 1680 |
{ |
| 1681 |
if(!$this->atAdminPanel) |
| 1682 |
{ |
| 1683 |
$uamOptions = $this->getAdminOptions(); |
| 1684 |
if($uamOptions['hide_post'] == 'true' || $uamOptions['hide_page'] == 'true') |
| 1685 |
{ |
| 1686 |
$args = array( 'numberposts' => -1); |
| 1687 |
$posts = get_posts($args); |
| 1688 |
|
| 1689 |
foreach($categories as $category) |
| 1690 |
{ |
| 1691 |
$count = 0; |
| 1692 |
|
| 1693 |
if($posts) |
| 1694 |
{ |
| 1695 |
foreach($posts as $cur_post) |
| 1696 |
{ |
| 1697 |
$post_cat_ids = array(); |
| 1698 |
$post_cats = get_the_category($cur_post->ID); |
| 1699 |
foreach($post_cats as $post_cat) |
| 1700 |
{ |
| 1701 |
$post_cat_ids[] = $post_cat->term_id; |
| 1702 |
} |
| 1703 |
|
| 1704 |
if(in_array($category->term_id, $post_cat_ids) ) |
| 1705 |
{ |
| 1706 |
if( ($uamOptions['hide_post'] == 'true' && $cur_post->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $cur_post->post_type == "page") ) |
| 1707 |
{ |
| 1708 |
if($this->check_access($cur_post->ID)) |
| 1709 |
$count++; |
| 1710 |
} |
| 1711 |
else |
| 1712 |
{ |
| 1713 |
$count++; |
| 1714 |
} |
| 1715 |
} |
| 1716 |
} |
| 1717 |
} |
| 1718 |
|
| 1719 |
if($count != 0) |
| 1720 |
{ |
| 1721 |
$category->count = $count; |
| 1722 |
$show_categories[] = $category; |
| 1723 |
} |
| 1724 |
|
| 1725 |
$categories = $show_categories; |
| 1726 |
} |
| 1727 |
} |
| 1728 |
} |
| 1729 |
|
| 1730 |
return $categories; |
| 1731 |
} |
| 1732 |
|
| 1733 |
function show_next_previous_post($sql) |
| 1734 |
{ |
| 1735 |
$uamOptions = $this->getAdminOptions(); |
| 1736 |
//if($uamOptions['hide_post'] == 'true') |
| 1737 |
//{ |
| 1738 |
$posts = get_posts(); |
| 1739 |
foreach($posts as $post) |
| 1740 |
{ |
| 1741 |
if(!$this->check_access($post->ID)) |
| 1742 |
$excluded_posts[] = $post->ID; |
| 1743 |
} |
| 1744 |
if($excluded_posts) |
| 1745 |
{ |
| 1746 |
$excluded_posts_str = implode(",", $excluded_posts); |
| 1747 |
$sql .= "AND ID NOT IN($excluded_posts_str)"; |
| 1748 |
} |
| 1749 |
//} |
| 1750 |
return $sql; |
| 1751 |
} |
| 1752 |
|
| 1753 |
function admin_output($post_id) |
| 1754 |
{ |
| 1755 |
if(!$this->atAdminPanel) |
| 1756 |
{ |
| 1757 |
global $current_user; |
| 1758 |
$cur_userdata = get_userdata($current_user->ID); |
| 1759 |
|
| 1760 |
$access = $this->get_access($post_id); |
| 1761 |
if($cur_userdata->wp_capabilities['administrator'] == 1 && ($access->restricted_by_posts || $access->restricted_by_categories)) |
| 1762 |
{ |
| 1763 |
$output = " [L]"; |
| 1764 |
} |
| 1765 |
return $output; |
| 1766 |
} |
| 1767 |
} |
| 1768 |
|
| 1769 |
function redirect_user() |
| 1770 |
{ |
| 1771 |
global $wp_query; |
| 1772 |
|
| 1773 |
if(!$this->check_access() && $uamOptions['redirect'] != 'false') |
| 1774 |
{ |
| 1775 |
$uamOptions = $this->getAdminOptions(); |
| 1776 |
|
| 1777 |
if($uamOptions['redirect'] == 'blog' || $uamOptions['redirect'] == 'custom_page') |
| 1778 |
{ |
| 1779 |
$host = $_SERVER['HTTP_HOST']; |
| 1780 |
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); |
| 1781 |
|
| 1782 |
if($uamOptions['redirect'] == 'blog') |
| 1783 |
$extra = ''; |
| 1784 |
elseif($uamOptions['redirect'] == 'custom_page') |
| 1785 |
$extra = $uamOptions['redirect_custom_page']; |
| 1786 |
|
| 1787 |
$url = "http://".$host.$uri."/".$extra; |
| 1788 |
} |
| 1789 |
elseif( $uamOptions['redirect'] == 'custom_url') |
| 1790 |
{ |
| 1791 |
$url = $uamOptions['redirect_custom_url']; |
| 1792 |
} |
| 1793 |
|
| 1794 |
|
| 1795 |
$cur_posts = $wp_query->get_posts(); |
| 1796 |
|
| 1797 |
$post_to_show = false; |
| 1798 |
|
| 1799 |
foreach($cur_posts as $cur_post) |
| 1800 |
{ |
| 1801 |
if($this->check_access()) |
| 1802 |
{ |
| 1803 |
$post_to_show = true; |
| 1804 |
break; |
| 1805 |
} |
| 1806 |
} |
| 1807 |
|
| 1808 |
if($url != "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"] && !$post_to_show) |
| 1809 |
{ |
| 1810 |
header("Location: $url"); |
| 1811 |
exit; |
| 1812 |
} |
| 1813 |
} |
| 1814 |
elseif(isset($_GET['getfile'])) |
| 1815 |
{ |
| 1816 |
$cur_id = $_GET['getfile']; |
| 1817 |
$cur_post = & get_post($cur_id); |
| 1818 |
|
| 1819 |
if ($cur_post->post_type == 'attachment' && $this->check_access($cur_post->ID)) |
| 1820 |
{ |
| 1821 |
$file = str_replace("http://".$_SERVER['HTTP_HOST']."/", "", $cur_post->guid); |
| 1822 |
$filename = basename($file); |
| 1823 |
|
| 1824 |
if (file_exists($file)) |
| 1825 |
{ |
| 1826 |
$len = filesize($file); |
| 1827 |
header('content-type: '.$cur_post->post_mime_type); |
| 1828 |
header('content-length: '.$len); |
| 1829 |
header('content-disposition: attachment; filename='.basename($file)); |
| 1830 |
|
| 1831 |
if($uamOptions['download_type'] == 'fopen') |
| 1832 |
{ |
| 1833 |
$fp=fopen($file, 'rb'); |
| 1834 |
|
| 1835 |
while ( ! feof($fp) ) |
| 1836 |
{ |
| 1837 |
set_time_limit(30); |
| 1838 |
$buffer = fread($fp, 1024); |
| 1839 |
echo $buffer; |
| 1840 |
} |
| 1841 |
exit; |
| 1842 |
} |
| 1843 |
else |
| 1844 |
{ |
| 1845 |
readfile($file); |
| 1846 |
exit; |
| 1847 |
} |
| 1848 |
} |
| 1849 |
else |
| 1850 |
{ |
| 1851 |
echo 'Error: File not found'; |
| 1852 |
} |
| 1853 |
} |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
function get_file($URL, $ID) |
| 1858 |
{ |
| 1859 |
$uamOptions = $this->getAdminOptions(); |
| 1860 |
|
| 1861 |
if($uamOptions['lock_file'] == 'true') |
| 1862 |
{ |
| 1863 |
$cur_id = $ID; |
| 1864 |
$cur_post = & get_post($cur_id); |
| 1865 |
$cur_parent_id = $cur_post->post_parent; |
| 1866 |
$cur_parent = & get_post($cur_parent_id); |
| 1867 |
|
| 1868 |
$type = explode("/", $cur_post->post_mime_type); |
| 1869 |
$type = $type[1]; |
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
$file_types = $uamOptions['locked_file_types']; |
| 1874 |
$file_types = explode(",", $file_types); |
| 1875 |
|
| 1876 |
if(in_array($type, $file_types)) |
| 1877 |
{ |
| 1878 |
if(strpos($cur_parent->guid, "?")) |
| 1879 |
$char = "&"; |
| 1880 |
else |
| 1881 |
$char = "?"; |
| 1882 |
|
| 1883 |
$URL = $cur_parent->guid.$char.'getfile='.$cur_post->ID; |
| 1884 |
} |
| 1885 |
} |
| 1886 |
return $URL; |
| 1887 |
} |
| 1888 |
} |
| 1889 |
} |
| 1890 |
|
| 1891 |
if (class_exists("UserAccessManager")) |
| 1892 |
{ |
| 1893 |
$userAccessManager = new UserAccessManager(); |
| 1894 |
} |
| 1895 |
|
| 1896 |
//Initialize the admin panel |
| 1897 |
if (!function_exists("UserAccessManager_AP")) { |
| 1898 |
function UserAccessManager_AP() |
| 1899 |
{ |
| 1900 |
global $userAccessManager; |
| 1901 |
|
| 1902 |
$userAccessManager->atAdminPanel = true; |
| 1903 |
|
| 1904 |
if (!isset($userAccessManager)) |
| 1905 |
{ |
| 1906 |
return; |
| 1907 |
} |
| 1908 |
if (function_exists('add_menu_page')) |
| 1909 |
{ |
| 1910 |
add_menu_page('User Access Manager', 'Access Manager', 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage')); |
| 1911 |
} |
| 1912 |
if (function_exists('add_submenu_page')) |
| 1913 |
{ |
| 1914 |
add_submenu_page('uam_usergroup', TXT_MANAGE_GROUP, TXT_MANAGE_GROUP, 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage')); |
| 1915 |
add_submenu_page('uam_usergroup', TXT_SETTING, TXT_SETTINGS, 9, 'uam_settings', array(&$userAccessManager, 'printAdminPage')); |
| 1916 |
} |
| 1917 |
if( function_exists( 'add_meta_box' )) |
| 1918 |
{ |
| 1919 |
add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'post', 'side' ); |
| 1920 |
add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'page', 'side' ); |
| 1921 |
} |
| 1922 |
|
| 1923 |
//Admin actions |
| 1924 |
add_action('manage_posts_custom_column', array(&$userAccessManager, 'add_post_column'), 9, 2); |
| 1925 |
add_action('manage_pages_custom_column', array(&$userAccessManager, 'add_post_column'), 9, 2); |
| 1926 |
add_action('save_post', array(&$userAccessManager, 'save_postdata'), 9); |
| 1927 |
add_action('delete_post', array(&$userAccessManager, 'remove_postdata'), 9); |
| 1928 |
|
| 1929 |
add_action('edit_user_profile', array(&$userAccessManager, 'show_user_profile'), 9); |
| 1930 |
add_action('profile_update', array(&$userAccessManager, 'save_userdata'), 9); |
| 1931 |
add_action('delete_user', array(&$userAccessManager, 'remove_userdata'), 9); |
| 1932 |
|
| 1933 |
//add_action('edit_category_add_form_before_button', array(&$userAccessManager, 'show_cat_add_form'), 9); |
| 1934 |
add_action('edit_category_edit_form_before_button', array(&$userAccessManager, 'show_cat_edit_form'), 9); |
| 1935 |
//add_action('created_term', array(&$userAccessManager, 'save_categorydata'), 9); |
| 1936 |
add_action('edit_category', array(&$userAccessManager, 'save_categorydata'), 9); |
| 1937 |
add_action('delete_category', array(&$userAccessManager, 'remove_categorydata'), 9); |
| 1938 |
|
| 1939 |
//Admin filters |
| 1940 |
add_filter('manage_posts_columns', array(&$userAccessManager, 'add_post_columns_header'), 9); |
| 1941 |
add_filter('manage_pages_columns', array(&$userAccessManager, 'add_post_columns_header'), 9); |
| 1942 |
add_filter('manage_users_columns', array(&$userAccessManager, 'add_user_columns_header'), 10); |
| 1943 |
add_filter('manage_users_custom_column', array(&$userAccessManager, 'add_user_column'), 10, 2); |
| 1944 |
add_filter('manage_categories_columns', array(&$userAccessManager, 'add_category_columns_header'), 9); |
| 1945 |
add_filter('manage_categories_custom_column', array(&$userAccessManager, 'add_category_column'), 10, 2); |
| 1946 |
} |
| 1947 |
} |
| 1948 |
|
| 1949 |
//Actions and Filters |
| 1950 |
if (isset($userAccessManager)) |
| 1951 |
{ |
| 1952 |
$uamOptions = $userAccessManager->getAdminOptions(); |
| 1953 |
|
| 1954 |
//install |
| 1955 |
register_activation_hook(__FILE__, array(&$userAccessManager, 'install')); |
| 1956 |
if(function_exists('register_uninstall_hook')) |
| 1957 |
register_uninstall_hook(__FILE__, array(&$userAccessManager, 'uninstall')); |
| 1958 |
elseif(function_exists('register_deactivation_hook')) |
| 1959 |
register_deactivation_hook(__FILE__, array(&$userAccessManager, 'uninstall')); |
| 1960 |
|
| 1961 |
//Actions |
| 1962 |
add_action('admin_menu', 'UserAccessManager_AP'); |
| 1963 |
|
| 1964 |
add_action('wp_head', array(&$userAccessManager, 'add_head_content'), 1); |
| 1965 |
|
| 1966 |
if($uamOptions['redirect'] != 'false' || isset($_GET['getfile'])) |
| 1967 |
add_action('template_redirect', array(&$userAccessManager, 'redirect_user'), 1); |
| 1968 |
|
| 1969 |
//Filters |
| 1970 |
add_filter('wp_get_attachment_url', array(&$userAccessManager, 'get_file'), 1, 2); |
| 1971 |
add_filter('the_posts', array(&$userAccessManager, 'show_post'), 1); |
| 1972 |
add_filter('get_pages', array(&$userAccessManager, 'show_page'), 1); |
| 1973 |
add_filter('get_terms', array(&$userAccessManager, 'show_category'), 1); |
| 1974 |
add_filter('get_next_post_where', array(&$userAccessManager, 'show_next_previous_post'), 1); |
| 1975 |
add_filter('get_previous_post_where', array(&$userAccessManager, 'show_next_previous_post'), 1); |
| 1976 |
} |
| 1977 |
|
| 1978 |
?> |